class Singleton {
    private static instance: Singleton;
    private eventMap:any = {
    };
    private constructor() {
        // 初始化代码
        window.addEventListener("message",(event:any)=>{
             let eventName = event.pluginMessag.moduleType;
             this.eventMap[eventName](event);
        });
    }
    public static getInstance(): Singleton {
        if (!Singleton.instance) {
            Singleton.instance = new Singleton();
        }
        return Singleton.instance;
    }
    public on(name:string,fn:Function){
         this.eventMap[name] = fn;
    }
}
 
// 获取单例对象
export const messageInstance = Singleton.getInstance();